<?php 
session_start();
require_once('twitteroauth/twitteroauth.php');
require_once('configuration.php');

$jtoret = json_decode($_GET['json']);
$database = mysql_connect("localhost", "root", "root");
if(!$database){
		echo "<br>Not Connected";
	} else {
		foreach($jtoret as $jtr)
		{
			$query = "SELECT `youtube_url` FROM tweets WHERE `id` = '".$jtr."'";
			$select = mysql_select_db('streamtube', $database);
			$reply = mysql_query($query);
			$links = array();
   	 		while ($row = mysql_fetch_array($reply)) {
    			$links[] = $row;
    		}
		}
		$str = "";
		foreach($links as $link)
		{
			$str = $str." ".$link['youtube_url'];
			$twitteroauth = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['user_oauth_token'], $_SESSION['user_oauth_token_secret']);
			$twitteroauth->post('statuses/update', array('status'=>$str));
			$str="";
		}
	}
mysql_close();
?>